﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="User.aspx.cs" Inherits="User_User" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="body" Runat="Server">

    
    <div style="background-color:White; padding:2.5%">
        <asp:Label ID="lbAssetHeading" runat="server" Text="Users" Font-Bold="True" 
            Font-Size="X-Large"></asp:Label>
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text="Select User: "></asp:Label>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="AccessDataSource1" DataTextField="Username" 
            DataValueField="Username">
            </asp:DropDownList>
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/Database.accdb" 
            SelectCommand="SELECT [Username] FROM [User]"></asp:AccessDataSource>
            <br />
            <br />
            
        <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="309px" 
            AutoGenerateRows="False" CellPadding="5" DataKeyNames="Username" 
            DataSourceID="AccessDataSource3" onitemdeleted="DetailsView1_ItemDeleted" 
            oniteminserted="DetailsView1_ItemInserted" 
            onitemupdated="DetailsView1_ItemUpdated" BorderStyle="None" 
            GridLines="None">
            <Fields>
                <asp:CommandField ButtonType="Button" ShowInsertButton="True" 
                    ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" >
                <ControlStyle CssClass="button" />
                <ItemStyle BackColor="#CCCCCC" />
                </asp:CommandField>
                <asp:BoundField DataField="Username" HeaderText="Username" ReadOnly="True" 
                    SortExpression="Username" />
                <asp:BoundField DataField="Password" HeaderText="Password" 
                    SortExpression="Password" />
                <asp:BoundField DataField="Firstname" HeaderText="Firstname" 
                    SortExpression="Firstname" />
                <asp:BoundField DataField="Surname" HeaderText="Surname" 
                    SortExpression="Surname" />
                <asp:BoundField DataField="User_Type" HeaderText="User_Type" 
                    SortExpression="User_Type" />
            </Fields>
        </asp:DetailsView>
            
            <asp:AccessDataSource ID="AccessDataSource3" runat="server" 
            DataFile="~/App_Data/Database.accdb" 
            DeleteCommand="DELETE FROM [User] WHERE (([Username] = ?) )" 
            InsertCommand="INSERT INTO [User] ([Username], [Password], [Firstname], [Surname], [User_Type]) VALUES (?, ?, ?, ?, ?)" 
            SelectCommand="SELECT * FROM [User] WHERE ([Username] = ?)" 
            UpdateCommand="UPDATE [User] SET [Password] = ?, [Firstname] = ?, [Surname] = ?, [User_Type] = ? WHERE (([Username] = ?) )">
                <DeleteParameters>
                    <asp:Parameter Name="Username" Type="String" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Username" Type="String" />
                    <asp:Parameter Name="Password" Type="String" />
                    <asp:Parameter Name="Firstname" Type="String" />
                    <asp:Parameter Name="Surname" Type="String" />
                    <asp:Parameter Name="User_Type" Type="String" />
                </InsertParameters>
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="Username" 
                        PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Password" Type="String" />
                    <asp:Parameter Name="Firstname" Type="String" />
                    <asp:Parameter Name="Surname" Type="String" />
                    <asp:Parameter Name="User_Type" Type="String" />
                    <asp:Parameter Name="Username" Type="String" />
                </UpdateParameters>
        </asp:AccessDataSource>
            
            <br />
            <br />
        <asp:Label ID="Label2" runat="server" Text="List of User Rights:"></asp:Label>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="5" DataKeyNames="Right_ID" DataSourceID="AccessDataSource2" 
            BorderColor="#CCCCCC" Font-Size="Small">
                <Columns>
                    <asp:BoundField DataField="Right_ID" HeaderText="Right_ID" ReadOnly="True" 
                        SortExpression="Right_ID" />
                    <asp:BoundField DataField="Right_Description" HeaderText="Right_Description" 
                        SortExpression="Right_Description" />
                </Columns>
            </asp:GridView>

        <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
            DataFile="~/App_Data/Database.accdb" SelectCommand="SELECT Rights.Right_ID, Rights.Right_Description
FROM Rights INNER JOIN User_Priviledges ON Rights.Right_ID = User_Priviledges.Right_ID
WHERE ([User_Priviledges.Username] = ?)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="?" 
                    PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:AccessDataSource>

    </div>
</asp:Content>

